< previous page page_206 next page >

Page 206
The data is in the byte array. Unfortunately, it's rather difficult to access fields of a structure when they are buried within a byte array. So we copy the byte array into a DEVMODE structure using the RtlMoveMemory function, as follows:
7017a6ead0e3c4111b47a554df321e9f.gif
' Copy the DEVMODE portion of the buffer into
' the dmOut buffer so we can use it
Call RtlMoveMemory(dmOut, dmOutBuf(0), Len(dmOut))
If dmOut.dmOrientation = DMORIENT_LANDSCAPE Then
   lblStatus.Caption = "Printer is in landscape mode"
Else
   lblStatus.Caption = "Printer is in portrait mode"
End If
' You can modify the contents of the dmout buffer, then
' copy the data to the dmInBuf buffer and
' call DocumentProperties with DM_IN_BUFFER to set the new values
Call ClosePrinter(hPrinter)
This example demonstrates how you can retrieve device data. The process is reversed if you want to set the device parameters: Copy the data from the output buffer to the input buffer (all of the data, not just the DEVMODE portion). Make any modifications to the DEVMODE portion of the buffer and set the appropriate bits in the dmFieldsbits field so that the device will know which parameters you are changing. Finally, call the DocumentProperties function with the DM_IN_BUFFER flag set in the fMode parameter.
There will be any number of situations where you'll have a Visual Basic declaration for a function that someone has given you or that you have figured out for yourself, and you'll be all set to use it in your program. Next thing you know, you'll be tearing your hair out because you can't get it to work or it causes constant memory exceptions. In many cases, the solution can be found by just reading the documentation carefully, because the answer is often (as it is with the DEVMODE structure) in the details.

 
< previous page page_206 next page >